local scene = director:createScene()

function scene:setUp(event)
    dbg.print("sceneMenu:setUp")
	
	local newScale = 320/director.displayWidth
	local newScaleY = 480/director.displayHeight
	
	if (io.open("scorejump.txt") == nil) then
	file = io.open("scorejump.txt", "w")
	file:write("999".."\n")
	file:write("999".."\n")
	file:write("999".."\n")
	file:close()
	end
	
	if (io.open("scoreevade.txt") == nil) then
	file = io.open("scoreevade.txt", "w")
	file:write("999".."\n")
	file:write("999".."\n")
	file:write("999".."\n")
	file:close()
	end
	
	local buttonContinue = director:createSprite(director.displayCenterX, -100, "img/buttonContinue.png")
	buttonContinue.xAnchor=0.5; buttonContinue.yAnchor=0.5
	buttonContinue.yScale=.9/newScaleY
	buttonContinue.xScale=1.1/newScale
	
    local buttonJump = director:createSprite(director.displayCenterX, director.displayCenterY, "img/buttonJump.png")
	buttonJump.xAnchor=0.5; buttonJump.yAnchor=0.5
	buttonJump.y = director.displayCenterY + 70/newScaleY
	buttonJump.yScale=.9/newScaleY
	buttonJump.xScale=1.1/newScale	
	
    local buttonEvade = director:createSprite(director.displayCenterX, director.displayCenterY, "img/buttonEvade.png")
	buttonEvade.xAnchor=0.5; buttonEvade.yAnchor=0.5
	buttonEvade.y =  buttonJump.y - 70/newScaleY
	buttonEvade.yScale=.9/newScaleY
	buttonEvade.xScale=1.1/newScale	
	
	local buttonScore = director:createSprite(director.displayCenterX, director.displayCenterY, "img/buttonScore.png")
	buttonScore.xAnchor=0.5; buttonScore.yAnchor=0.5
	buttonScore.y =  buttonJump.y - 140/newScaleY
	buttonScore.yScale=.9/newScaleY
	buttonScore.xScale=1.1/newScale	
	
	local buttonInstructions = director:createSprite(director.displayCenterX, director.displayCenterY, "img/buttonInstructions.png")
	buttonInstructions.xAnchor=0.5; buttonInstructions.yAnchor=0.5
	buttonInstructions.y =  buttonJump.y - 210/newScaleY
	buttonInstructions.yScale=.9/newScaleY
	buttonInstructions.xScale=1.1/newScale	
	
	function buttonContinue:touch(event)
		if (event.phase == 'began') then
			system:sendEvent("moveToSceneGame")
		end
	end
	buttonContinue:addEventListener('touch', buttonContinue)
	
	function buttonJump:touch(event)
		if (event.phase == 'began') then
			if (gameStats == "pause") then
				gameStats = "changeGame"
			end
			selectGame = "jump"
			system:sendEvent("moveToSceneGame")
		end
	end
	buttonJump:addEventListener('touch', buttonJump)
	
	function buttonEvade:touch(event)
		if (event.phase == 'began') then
			if (gameStats == "pause") then
				gameStats = "changeGame"
			end
			selectGame = "evade"
			system:sendEvent("moveToSceneGame")
		end
	end
	buttonEvade:addEventListener('touch', buttonEvade)

	function buttonInstructions:touch(event)
		if (event.phase == 'began') then
			system:sendEvent("moveToSceneInstructions")
		end
	end
	buttonInstructions:addEventListener('touch', buttonInstructions)
	
	function buttonScore:touch(event)
		if (event.phase == 'began') then
			system:sendEvent("moveToSceneScore")
		end
	end
	buttonScore:addEventListener('touch', buttonScore)
	
	if (gameStats == "pause") then
		buttonContinue.y = director.displayCenterY + 140/newScaleY
		buttonContinue.isVisible = true
	else
		buttonContinue.y = -100
		buttonContinue.isVisible = false
	end
end

function scene:tearDown(event)
    dbg.print("sceneMenu:tearDown")
end

scene:addEventListener({"setUp", "tearDown"}, scene)

return scene  -- We must return the scene object!